<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>

	<script type="text/javascript">
		window.onload=function(){
			let obtn =document.getElementById('btn');

			obtn.onclick=function(){
				if(window.navigator.geolocation){
					navigator.geolocation.getCurrentPosition(res=>{
						alert('成功')
					},err=>{
						alert('失败')
					},{

						timeout:2000,//2s没有返回位置则返回错误
						emnableHighAccuracy:true,//高精度模式
						maximumAge:60*1000//60s后清除位置缓存
						
					});

				}else{
					alert('你的浏览器不支持geolacvation')
				}
			}

		}
	</script>
</head>
<body>
	<input type="button" id="btn" value="定位" name="">
</body>
</html>